<template>
  <el-dialog
    :title="title"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="1200px"
    :before-close="cancel">
    <Type1 :data="data" v-if="type == 1" />
    <Type4 :data="data" v-if="type == 4" />
    <Type5 :data="data" v-if="type == 5" />
    <Type8 :data="data" v-if="type == 8" />
    <Type9 :data="data" v-if="type == 9" />
    <Type10 :data="data" v-if="type == 10" />
    <Type13 :data="data" v-if="type == 13" />
    <Type15 :data="data" v-if="type == 15" />
    <Type16 :data="data" v-if="type == 16" />
    <Type17 :data="data" v-if="type == 17" />
    <Type18 :data="data" v-if="type == 18" />
    <Type19 :data="data" v-if="type == 19" />

    <!-- <Type21 :data="data" :FormData = 'FormData' v-if="type == 21" /> -->
    <!-- *************************************type ==8 end ******************************** -->
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">
        <!-- 关闭 -->
        {{ $t('关闭') }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import handleTableSum from '@/utils/handleSum'
import Type1 from './type1.vue'
import Type4 from './type4.vue'
import Type5 from './type5.vue'
import Type9 from './type9.vue'
import Type8 from './type8.vue'
import Type10 from './type10.vue'
import Type13 from './type13.vue'
import Type15 from './type15.vue'
import Type16 from './type16.vue'
import Type17 from './type17.vue'
import Type18 from './type18.vue'
import Type19 from './type19.vue'
export default {
  components: {
    Type1,
    Type4,
    Type5,
    Type8,
    Type9,
    Type10,
    Type13,
    Type15,
    Type16,
    Type17,
    Type18,
    Type19,
},
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    FormData : {
      type: Object,
      default: () => {},
    },
    /**
     * data
     */
    data: {
      type: Array,
      default: () => [],
    },
    /**
     * 标题
     */
    title: {
      type: String,
      required: true,
    },
    /**
     * type
     */
    type: {
      type: [String, Number],
      required: true,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      queryParams: {},
    }
  },
  watch: {
    show: function (newValue) {
      if (newValue) {
        // console.log(` ==>`, JSON.parse(JSON.stringify(this.data)))
      }
    },
  },
  methods: {
    handleReceiveAddress(row) {
      return (
        (row.address1 || '') +
        (row.address2 || '') +
        (row.address3 || '') +
        (row.address4 || '') +
        (row.address5 || '') +
        (row.address6 || '')
      )
    },
    handleNeedSumData() {
      let needSumFieldList = []
      let sumText = '总价'
      let offset = 1
      switch (this.type) {
        case 1:
          needSumFieldList = [
            'handleNum',
            'handleWaitPayNum',
            'handlePayNum',
            'payTotal',
            'waitPayTotal',
            'totalPrice',
          ]
          break
        case 2:
          break
        case 3:
          needSumFieldList = ['bundleFee', 'deliveryFee']
          break
        case 4:
          needSumFieldList = ['turnover']
          break
        default:
          break
      }
      return {
        needSumFieldList,
        sumText,
        offset,
      }
    },
    handleSum(param) {
      /**
       * 需要进行统计的字段
       */
      const { needSumFieldList, offset, sumText } = this.handleNeedSumData()
      const data = handleTableSum(param, needSumFieldList, sumText, offset)
      console.log(`data ==>`, JSON.parse(JSON.stringify(data)))
      return data
    },

    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss"></style>
